package org.huawei260.TiKu.ODsuanfa;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 3115 【贪心】2024D-有效子字符串
 * @version: 1.0
 */
import java.util.Scanner;
public class D_2024D_3115__贪心_有效子字符串 { // 92.3%

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			String s = sc.nextLine();
			String l = sc.nextLine();

			System.out.println(getResult(s, l));
		}

		public static int getResult(String s, String l) {
			int i = 0;
			int j = 0;

			while (i < s.length() && j < l.length()) {
				if (s.charAt(i) == l.charAt(j)) {
					i++;
				}
				j++;
			}

			if (i == s.length()) return j - 1;
			else return -1;
		}
	}